import time
from selenium.webdriver.common.by import By
from selenium import webdriver

from common.basepage import Basepage
from common.yaml_handler import result
Host = result['Host']


class EnterprisePage(Basepage):
    url = Host + '/project/enterprise'

    """存放元素定位"""
    # 修改按钮
    edit = (By.CLASS_NAME, 'fixed-edit')
    # 区域选择框
    region = (By.XPATH, "//input[@placeholder='请选择项目所在地址']")
    # 省
    province = (By.XPATH, "//span[contains(text(), '山西省')]")
    # 市
    city = (By.XPATH, "//span[contains(text(), '太原市')]")
    # 区
    area = (By.XPATH, "//span[contains(text(), '小店区')]")
    # 公司地址
    company_address = (By.XPATH, "//label[contains(text(), '公司地址')]//following-sibling::div//input")
    # 联系人
    contacts = (By.XPATH, "//label[contains(text(), '联系人')]//following-sibling::div//input")
    # 联系电话
    contact_number = (By.XPATH, "//label[contains(text(), '联系电话')]//following-sibling::div//input")
    # 保存按钮
    preservation = (By.XPATH, "//button[@class='el-button submitbutton el-button--primary']")

    def edit_test(self, address, contacts, contact_number):
        """编辑企业信息"""
        driver = self.driver
        # 点击修改
        # driver.find_element(*self.edit).click()
        self.click(self.edit)
        # 点击区域,下拉选择框
        # driver.find_element(*self.region).click()
        self.click(self.region)
        # 选择省市区
        # driver.find_element(*self.province).click()
        self.click(self.province)
        # driver.find_element(*self.city).click()
        self.click(self.city)
        # driver.find_element(*self.area).click()
        self.click(self.area)
        time.sleep(2)
        # 清空地址并输入
        driver.find_element(*self.company_address).clear()
        driver.find_element(*self.company_address).send_keys(address)
        # 清空联系人并输入
        driver.find_element(*self.contacts).clear()
        driver.find_element(*self.contacts).send_keys(contacts)
        # 清空电话并输入
        driver.find_element(*self.contact_number).clear()
        driver.find_element(*self.contact_number).send_keys(contact_number)
        # 保存
        # driver.find_element(*self.preservation).click()
        self.click(self.preservation)

        # 提取新增断言
        # el = self.driver.find_elment(By.XPATH, f'//*[text="{name}"]')
